﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace DataTestFramework.Infrastructure
{
    public static class DataInitializer
    {
        private static readonly Stopwatch Watch = new Stopwatch();

        public static void Initialize()
        {
            Console.WriteLine("========初始化数据开始========");
            Watch.Start();
            Database.SetInitializer(new SampleData());
            using (var db = new TestContext())
            {
                db.Database.Initialize(false);
            }
            Watch.Stop();
            Console.WriteLine("========初始化数据结束========");
            Console.WriteLine("数据库初始化完成，耗时{0}", Watch.Elapsed);
            Console.WriteLine("当前数据库中拥有数据如下：");
            using (var db = new TestContext())
            {
                Console.WriteLine("产品目录信息：{0}条", db.Categories.Count());
                Console.WriteLine("产品信息：{0}条", db.Products.Count());
                Console.WriteLine("客户信息：{0}条", db.Customers.Count());
                Console.WriteLine("订单信息：{0}条", db.Orders.Count());
                Console.WriteLine("订单明细信息：{0}条", db.OrderDetails.Count());
            }
        }
    }
}
